define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.form.fk_group = params.fk_group;
	$scope.form.id = params.fk_role;

	httpService.post(app.urls.role_selectById,{"id":params.fk_role},function(data){
		if("0000" === data.code){
			$scope.form.name = data.data.name;
			$scope.form.type = data.data.type;
		}else{
			alert(data.msg);
		}
	});
	//查询分组
	httpService.post(app.urls.role_group_selectByType,{},function(data){
		if("0000" === data.code){
			$scope.roles = data.data;
		}else{
			alert(data.msg);
		}
	});
	$scope.saveForm = function(){
		if($scope.formCheck()){
			httpService.post(app.urls.role_selectIfExit,$scope.form,function(data){
				if("0000" === data.code){
					if(data.data.length == 0){
						httpService.post(app.urls.role_update,$scope.form,function(data){
							if("0000" === data.code){
								var data = {id:params.fk_role,type:params.type};
								eventBusService.publish("content.pageGroup.reload",data);
								eventBusService.publish("modal.page.close",{});
							}else{
								alert(data.msg);
							}
						});
					}else{
						alert("该角色已存在");
					}
				}else{
					alert(data.msg);
				}
			});
		}
	}
}}});